package com.bajiao.admin.controller.user;

import cn.hutool.core.util.StrUtil;
import com.bajiao.admin.base.AdminBaseController;
import com.bajiao.admin.query.QueryGenerator;
import com.bajiao.common.system.vo.LoginUser;
import com.bajiao.common.util.oConvertUtils;
import com.bajiao.entity.recharge.RechargeMenu;
import com.bajiao.service.recharge.RechargeMenuService;
import com.bajiao.vo.user.UserAdmin;
import com.bajiao.vo.user.UserVerify;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.bajiao.common.api.vo.Result;
import com.bajiao.common.util.RedisUtil;
import com.bajiao.common.util.StringUtils;
import com.bajiao.common.web.BaseController;
import com.bajiao.entity.user.User;
import com.bajiao.service.user.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jodd.util.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T;
import org.apache.shiro.SecurityUtils;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description: 普通用户
 * @Author: FanJq
 * @Date: 2024-10-11
 * @Version: V1.0
 */
@Slf4j
@Api(tags = "普通用户")
@RestController
@RequestMapping("/user")
public class UserController extends AdminBaseController<User, UserService> {
    public static void main(String[] args) {
        String a = "344.00";
        BigDecimal b = new BigDecimal(a);
        BigDecimal c = b.multiply(new BigDecimal(100));
        System.out.println(c.intValue());
    }

    @Resource
    private UserService userService;

    @ApiOperation(value = "普通用户-分页列表查询", notes = "普通用户-分页列表查询")
    @GetMapping(value = "/list")
    public Result<?> queryPageList(UserAdmin request) {
        startPage();
        List<UserAdmin> userAdminList = userService.getUserAdminList(request);
        return Result.ok(getDataTable(userAdminList));
    }

    @ApiOperation(value = "核销列表", notes = "核销列表")
    @GetMapping(value = "/verify/list")
    public Result<?> getVerifyList(String keywords, String orderNo, String storeTitle, String title, String createTimeBegin, String createTimeEnd) {
        startPage();
        List<UserVerify> resultList = userService.getVerifyList(keywords, orderNo, storeTitle, title, createTimeBegin, createTimeEnd);
        return Result.ok(getDataTable(resultList));
    }

    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(UserAdmin request, String fileName) {
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        // Step.2 获取导出数据
        List<UserAdmin> exportList = userService.getUserAdminList(request);
        // Step.3 AutoPoi 导出Excel
        ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
        mv.addObject(NormalExcelConstants.FILE_NAME, fileName); //此处设置的filename无效 ,前端会重更新设置一下
        mv.addObject(NormalExcelConstants.CLASS, UserAdmin.class);
        mv.addObject(NormalExcelConstants.PARAMS, new ExportParams(fileName, "导出人:" + sysUser.getRealname(), fileName));
        mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
        return mv;
    }

    @RequestMapping(value = "/verify/exportXls")
    public ModelAndView verifyExportXls(String keywords, String orderNo, String storeTitle, String title, String createTimeBegin, String createTimeEnd, String fileName) {
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        // Step.2 获取导出数据
        List<UserVerify> exportList = userService.getVerifyList(keywords, orderNo, storeTitle, title, createTimeBegin, createTimeEnd);
        // Step.3 AutoPoi 导出Excel
        ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
        mv.addObject(NormalExcelConstants.FILE_NAME, fileName); //此处设置的filename无效 ,前端会重更新设置一下
        mv.addObject(NormalExcelConstants.CLASS, UserVerify.class);
        mv.addObject(NormalExcelConstants.PARAMS, new ExportParams(fileName, "导出人:" + sysUser.getRealname(), fileName));
        mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
        return mv;
    }
}
